package com.example.bms.serviceimpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.bms.entity.JudgeQuestion;
import com.example.bms.mapper.JudgeQuestionMapper;
import com.example.bms.service.JudgeQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;


/**
 * @apiNote 用于对判断题的增加和查询
 * @author
 * @email 1605009600@qq.com
 * @since 1.0.0
 */
@Service
@Transactional
public class JudgeQuestionServiceImpl implements JudgeQuestionService {

    @Autowired
    private JudgeQuestionMapper judgeQuestionMapper;


    /**
     * @apiNote 查询判断题题库
     * @author
     * @param paperId 试卷Id
     * @email 1605009600@qq.com
     * @return List<JudgeQuestion>
     * @since 1.0.0
     */
    public List<JudgeQuestion> findByIdAndType(Integer paperId) {
        return judgeQuestionMapper.findByIdAndType(paperId);
    }


    /**
     * @apiNote 查询判断题题库
     * @author
     * @param page 页码
     * @email 1605009600@qq.com
     * @return IPage<JudgeQuestion>
     * @since 1.0.0
     */
    @Override
    public IPage<JudgeQuestion> findAll(Page<JudgeQuestion> page) {
        return judgeQuestionMapper.findAll(page);
    }


    /**
     * @apiNote 查询最后一条记录的questionId
     * @author
     * @email 1605009600@qq.com
     * @return JudgeQuestion
     * @since 1.0.0
     */
    @Override
    public JudgeQuestion findOnlyQuestionId() {
        return judgeQuestionMapper.findOnlyQuestionId();
    }


    /**
     * @apiNote 插入一个判断题
     * @author
     * @param judgeQuestion 判断题实体对象
     * @email 1605009600@qq.com
     * @return int类型，插入成功返回1，插入失败返回0
     * @since 1.0.0
     */
    @Override
    public int add(JudgeQuestion judgeQuestion) {
        return judgeQuestionMapper.add(judgeQuestion);
    }


    /**
     * @apiNote 查询questionId
     * @author
     * @param subject 科目
     * @param pageNo  页码
     * @email 1605009600@qq.com
     * @return List<Integer>
     * @since 1.0.0
     */
    @Override
    public List<Integer> findBySubject(String subject, Integer pageNo) {
        return judgeQuestionMapper.findBySubject(subject,pageNo);
    }
}
